﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace luanvanFinal
{
    class clsReqChange
    {
        String idChange;
        int idModifier;
        int idProject;
        Nullable<DateTime> dateSubmitted = null;
        Nullable<DateTime> dateUpdate = null;
        String tittle;
        String description;
        String originatorPriority;
        String impPriority;
        String response;
        String status;
        int originator;

        public String IdChange
        {
            get { return idChange; }
            set { idChange = value; }
        }
        public int IdModifier
        {
            get { return idModifier; }
            set { idModifier = value; }
        }
        public int IdProject
        {
            get { return idProject; }
            set { idProject = value; }
        }
        public Nullable<DateTime> DateSubmitted
        {
            get { return dateSubmitted; }
            set { dateSubmitted = value; }
        }
        public Nullable<DateTime> DateUpdate
        {
            get { return dateUpdate; }
            set { dateUpdate = value; }
        }
        public String Tittle
        {
            get { return tittle; }
            set { tittle = value; }
        }
        public String Description
        {
            get { return description; }
            set { description = value; }
        }
        public String OriginatorPriority
        {
            get { return originatorPriority; }
            set { originatorPriority = value; }
        }
        public String ImpPriority
        {
            get { return impPriority; }
            set { impPriority = value; }
        }
        public String Response
        {
            get { return response; }
            set { response = value; }
        }
        public String Status
        {
            get { return status; }
            set { status = value; }
        }
        public int Originator
        {
            get { return originator; }
            set { originator = value; }
        }
        public clsReqChange()
        {
            idChange="";
            idModifier=0;
            idProject=0;
            Nullable<DateTime> dateSubmitted = null;
            Nullable<DateTime> dateUpdate = null;
            tittle="";
            description="";
            originatorPriority="";
            impPriority="";
            response="";
            status="";
            originator = 0;
        }

        public void insertReqChange()
        {
            clsConnect ketnoi = new clsConnect();
            ketnoi.openConnection();
            try
            {
                SqlCommand sqlcmd = new SqlCommand("insertReqChange", ketnoi.Connection);
                sqlcmd.CommandType = CommandType.StoredProcedure;
                sqlcmd.Parameters.Add("@idChange", SqlDbType.NVarChar).Value = this.idChange;
                sqlcmd.Parameters.Add("@idModifier", SqlDbType.Int).Value = this.idModifier;
                sqlcmd.Parameters.Add("@idProject", SqlDbType.Int).Value = this.idProject;
                sqlcmd.Parameters.Add("@dateSubmitted", SqlDbType.DateTime).Value = this.dateSubmitted;
                sqlcmd.Parameters.Add("@dateUpdate", SqlDbType.DateTime).Value = this.dateUpdate;
                sqlcmd.Parameters.Add("@title", SqlDbType.NVarChar).Value = this.tittle;
                sqlcmd.Parameters.Add("@description", SqlDbType.NVarChar).Value = this.description;
                sqlcmd.Parameters.Add("@originatorPriority", SqlDbType.NVarChar).Value = this.originatorPriority;
                sqlcmd.Parameters.Add("@impPriority", SqlDbType.NVarChar).Value = this.impPriority;
                sqlcmd.Parameters.Add("@response", SqlDbType.NVarChar).Value = this.response;
                sqlcmd.Parameters.Add("@status", SqlDbType.NVarChar).Value = this.status;
                sqlcmd.Parameters.Add("@originator", SqlDbType.Int).Value = this.originator;
                sqlcmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Dữ liệu đã tồn tại hoặc không hợp lệ!!!" + ex.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            ketnoi.closeConnection();
        }        

        public void updateReqChange()
        {
            clsConnect ketnoi = new clsConnect();
            ketnoi.openConnection();
            try
            {
                SqlCommand sqlcmd = new SqlCommand("updateReqChange", ketnoi.Connection);
                sqlcmd.CommandType = CommandType.StoredProcedure;
                sqlcmd.Parameters.Add("@idChange", SqlDbType.NVarChar).Value = this.idChange;
                sqlcmd.Parameters.Add("@idModifier", SqlDbType.Int).Value = this.idModifier;
                sqlcmd.Parameters.Add("@idProject", SqlDbType.Int).Value = this.idProject;
                sqlcmd.Parameters.Add("@dateSubmitted", SqlDbType.DateTime).Value = this.dateSubmitted;
                sqlcmd.Parameters.Add("@dateUpdate", SqlDbType.DateTime).Value = this.dateUpdate;
                sqlcmd.Parameters.Add("@title", SqlDbType.NVarChar).Value = this.tittle;
                sqlcmd.Parameters.Add("@description", SqlDbType.NVarChar).Value = this.description;
                sqlcmd.Parameters.Add("@originatorPriority", SqlDbType.NVarChar).Value = this.originatorPriority;
                sqlcmd.Parameters.Add("@impPriority", SqlDbType.NVarChar).Value = this.impPriority;
                sqlcmd.Parameters.Add("@response", SqlDbType.NVarChar).Value = this.response;
                sqlcmd.Parameters.Add("@status", SqlDbType.NVarChar).Value = this.status;
                sqlcmd.Parameters.Add("@originator", SqlDbType.Int).Value = this.originator;
                sqlcmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Dữ liệu đã tồn tại hoặc không hợp lệ!!!" + ex.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            ketnoi.closeConnection();
        }

        public void deleteReqChange()
        {
            clsConnect ketnoi = new clsConnect();
            ketnoi.openConnection();
            try
            {
                SqlCommand sqlcmd = new SqlCommand("deleteReqChange", ketnoi.Connection);
                sqlcmd.CommandType = CommandType.StoredProcedure;
                sqlcmd.Parameters.Add("@idChange", SqlDbType.NVarChar).Value = this.idChange;
                sqlcmd.Parameters.Add("@idProject", SqlDbType.Int).Value = this.idProject;
                sqlcmd.ExecuteNonQuery();
                MessageBox.Show("You have delete success !!!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch
            {
                MessageBox.Show("You have error while deleting project!!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            ketnoi.closeConnection();
        }
        public void deleteReqChangeByIdProject()
        {
            clsConnect ketnoi = new clsConnect();
            ketnoi.openConnection();
            try
            {
                SqlCommand sqlcmd = new SqlCommand("deleteReqChangeByIdProject", ketnoi.Connection);
                sqlcmd.CommandType = CommandType.StoredProcedure;
                //sqlcmd.Parameters.Add("@idChange", SqlDbType.NVarChar).Value = this.idChange;
                sqlcmd.Parameters.Add("@idPro", SqlDbType.Int).Value = this.idProject;
                sqlcmd.ExecuteNonQuery();
                //MessageBox.Show("You have delete success !!!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch
            {
                MessageBox.Show("You have error while deleting!!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            ketnoi.closeConnection();
        }
    }
}
